package com.cg.design.graphicdesignpattern.iterator;

/**
 * 表示书架的类
 *
 * @program: LeetCode->BookShelf
 * @description: 表示书架的类
 * @author: cg
 * @create: 2022-03-17 21:49
 **/
public class BookShelf implements Aggregate {
    private Book[] books;
    private int last = 0;

    public BookShelf(int maxSize) {
        books = new Book[maxSize];
    }

    public Book getBookAt(int index) {
        return books[index];
    }

    public void appendBook(Book book) {
        this.books[last] = book;
        last++;
    }

    public int getLength(){
        return last;
    }

    @Override
    public Iterator<Book> iterator() {
        return new BookShelfIterator(this);
    }

}
